package com.android.jianboshi.dialog;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;

import com.android.baselibrary.dialog.BaseDialogFragment;
import com.android.baselibrary.tool.SPUtil;
import com.android.baselibrary.util.DateUtil;
import com.android.baselibrary.util.Util;
import com.android.jianboshi.R;
import com.android.jianboshi.constants.SPConstants;
import com.android.jianboshi.manager.BoxingHelper;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/8/29.
 */

public class Boxing_FreeStyleResult_DialogFragment extends BaseDialogFragment {

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_title1)
    TextView tv_title1;
    @BindView(R.id.tv_title2)
    TextView tv_title2;
    @BindView(R.id.tv_title3)
    TextView tv_title3;
    @BindView(R.id.tv_title4)
    TextView tv_title4;
    @BindView(R.id.tv_content1)
    TextView tv_content1;
    @BindView(R.id.tv_content2)
    TextView tv_content2;
    @BindView(R.id.tv_content3)
    TextView tv_content3;
    @BindView(R.id.tv_content4)
    TextView tv_content4;

    int type;

    public static final String Param_Time = "Param_Time";
    public static final String Param_Hits = "Param_Hits";
    public static final String Param_Avg_Power = "Param_AVG_Power";
    public static final String Param_Kcal = "Param_Kcal";

    int time;
    int hits;
    double powerAvg;
    double kcal;


    @Override
    protected int getLayoutId() {
        return R.layout.dialog_boxing_freestyle_result;
    }

    @Override
    protected void initData() {
        powerAvg = BoxingHelper.getPowerByUnit(mContext,powerAvg);
        tv_title1.setText(getString(R.string.freestyle_tips_time));
        tv_title2.setText(getString(R.string.freestyle_tips_times));
        tv_title3.setText(getString(R.string.freestyle_tips_power));
        tv_title4.setText(getString(R.string.freestyle_tips_kal));

        if (type == 0) {
            tv_title.setText(getString(R.string.freestyle_tips_title_result));
        } else {
            tv_title.setText(getString(R.string.freestyle_tips_title_history));
        }

        int unit = SPUtil.getIntValue(mContext, SPConstants.Unit, 0);
        String unitStr = "";
        if (unit == 0) {
            unitStr = getString(R.string.power_unit_unit1);
        } else {
            unitStr = getString(R.string.power_unit_unit2);
        }

        //训练时长：00:00:00
        //击打次数：100次
        //平均力量：100
        //卡路里数：10000
        tv_content1.setText("" + DateUtil.generateTime(time));
        tv_content2.setText("" + hits + " "+ getString(R.string.freestyle_tips_unit_times));
        tv_content3.setText("" + Util.numDecimalFormat(powerAvg + "", 1) +  " "+ unitStr);
        tv_content4.setText("" + Util.numDecimalFormat(kcal + "", 1) + " Kcal");

    }

    @Override
    protected void initView() {


    }

    @Override
    protected boolean setCanceledOnTouchBACK() {
        return true;
    }

    @Override
    protected int getShowDirection() {
        return BaseDialogFragment.Direction_FadeIn;
    }

    @Override
    public void setData(Map<String, Object> params) {
        if (params != null) {
            type = (int) params.get("type");
            time = (int) params.get(Boxing_FreeStyleResult_DialogFragment.Param_Time);
            hits = (int) params.get(Boxing_FreeStyleResult_DialogFragment.Param_Hits);
            powerAvg = (double) params.get(Boxing_FreeStyleResult_DialogFragment.Param_Avg_Power);
            kcal = (double) params.get(Boxing_FreeStyleResult_DialogFragment.Param_Kcal);


        }
    }

    public static BaseDialogFragment showDialog(FragmentActivity activity, Map<String, Object> params) {
        Boxing_FreeStyleResult_DialogFragment dialogFragment = new Boxing_FreeStyleResult_DialogFragment();
        dialogFragment.setData(params);
        dialogFragment.show(activity.getSupportFragmentManager(), "");
        return dialogFragment;
    }


    @OnClick({R.id.csb_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.csb_ok:  //确定
                dismissWithAnim();
                break;
        }
    }


}
